DESede
This algorithm, known as triple-DES, is a 64-bit block cipher with a 192-bit key, although 24 bits of the key are parity bits. This algorithm works by splitting the 192-bit key into three 64-bit keys and then applying the basic DES cipher, first in the encrypt mode, second in the decrypt mode, and finally in the encrypt mode. The algorithm is described in ANSI X9.17. It is also possible to use a double-length key (128 bits), in this case the first key is reused as the final key.
DESede cipher initialization
This cipher supports both ECB and CBC modes, and can be used with NoPadding or PKCS5Padding. To create an instance of this class, use the Cipher.getInstance() method with “SAFENET” as the provider and one of the following strings as the transformation:
-
DESede
-
DESede/ECB/NoPadding
-
DESede/ECB/PKCS5Padding
-
DESede/CBC/NoPadding
-
DESede/CBC/PKCS5Padding
Using the “DESede” transformation, the Cipher will default to ECB and NoPadding
If the NoPadding mode is selected, the input data must be a multiple of 8 bytes; otherwise, the encrypted or decrypted result will be truncated. In PKCS5Padding, arbitrary data lengths are accepted; the ciphertext will be padded to a multiple of 8 bytes, as described in PKCS#5. The decryption process will remove the padding from the data so that the correct plaintext is returned.
This Cipher will accept a javax.crypto.spec.SecretKeySpec or au.com.safenet.crypto.provider.CryptokiSecretKey as the key parameter during initialization.
When the Cipher is initialized in CBC mode, the Initialization Vector (IV) can be specified by passing a javax.crypto.spec.IvParameterSpec instance to the Cipher.init() method. When decrypting in this mode, a valid IV must be specified in the Cipher.init() method. For encryption, however, a random IV will be generated if none is specified (the IV can be retrieved using the Cipher.getIV() method).
The IV can be provided as a java.security.AlgorithmParameters or a javax.crypto.spec.IvParameterSpec instance. If the initialization is done using an AlgorithmParameters instance, it must be convertible to an IvParameterSpec using the AlgorithmParameters.getParameterSpec() method.
This Cipher does not support the Cipher.getParameters() method; this method will always return null
. The only supported parameter for this class is the initialization vector, which can be determined using the Cipher.getIV() method.
DESede key
The DESede Cipher requires either a SecretKeySpec or ProtectToolkit-J provider DESede Key during initialization. The DESede key may be either a double- or triple-length key.
To create an appropriate SecretKeySpec, pass a 16 or 24-byte array and the algorithm name “DESede” to the SecretKeySpec constructor. For example:
byte[] keyBytes = { 0x41, 0x22, 0x35, 0x17,
0x39, 0xDB, 0xDC, 0xEF
0x11, 0x93, 0x55, 0x67,
0x39, 0xAC, 0xCD, 0xFF };
SecretKeySpec desEdeKey = new SecretKeySpec(keyBytes,
“DESede”);
Alternatively, a random ProtectToolkit-J DESede key can be generated using the KeyGenerator as described in section Public keys, or a provider-independent form as described in section Key specifications. The DESede key can also be stored in the ProtectToolkit-J KeyStore, as described in Key storage.
The ProtectToolkit-J DESede key will return the string “DESede” as its algorithm name, and “RAW” as its encoding. However, since the key is stored within the hardware, the actual key encoding may not be available.
The key value can only be extracted from a key if the associated Cryptoki key is not marked as Sensitive. The keys generated in ProtectToolkit-J will always be marked as sensitive. It is possible, however, to access any Cryptoki keys stored on the device, and it is possible that the attributes of these keys have been modified.
DESede KeyGenerator
The DESede KeyGenerator is used to generate random DESede double or triple length keys. The generated key will be a hardware key that has the Cryptoki CKA_EXTRACTABLE and CKA_SENSITIVE attributes set. Since these keys are marked as Sensitive, their getEncoded() method will return null
.
During initialization, the strength parameter may be 128 to specify a double length key or 196 to specify a triple-length key. If no strength is specified, a triple-length key will be generated. The random parameter is ignored as the hardware includes a cryptographically-secure random source.
Keys generated using the KeyGenerator are not thread-safe. That is, a ProtectToolkit-J Key instance can only be used by a single Cipher instance (as well as a single MAC instance) at any given time. See Key generation for information on threading and ProtectToolkit-J keys.
DESede SecretKeyFactory
The DESede SecretKeyFactory is used to construct ProtectToolkit-J keys from their provider-independent form. The provider-independent form of the DESede key is the javax.crypto.spec.DESedeKeySpec class.
Keys generated using the SecretKeyFactory are not thread-safe. That is, a ProtectToolkit-J Key instance can only be used by a single Cipher instance (as well as a single MAC instance) at any given time. See Key generation for information on threading and ProtectToolkit-J keys.
For example, to create the provider based key from its provider independent form (in this case we are generating a triple-length key; specify 16 bytes for a double-length key):
byte[] keyBytes = { 0x41, 0x22, 0x35, 0x17,
0x39, 0xDB, 0xDC, 0xEF,
0x39, 0xDF, 0x28, 0x94,
0x11, 0x93, 0x55, 0x67,
0x11, 0x93, 0x55, 0x67,
0x39, 0xAC, 0xCD, 0xFF };
DESedeKeySpec desEdeKeySpec = new DESedeKeySpec(keyBytes);
SecretKeyFactory desEdeKeyFact =
SecretKeyFactory.getInstance(“DESede”, “SAFENET”);
SecretKey desEdeKey =
desEdeKeyFact.generateSecret(desEdeKeySpec);
DESede example code
See DES example code for the simple DES example. To convert the example to use DESede, use “DESede” in place of “DES”.